﻿using ESRI.ArcGIS.Geodatabase;
using Inovout.Gis;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.DataSourcesGDB;

namespace Inovout.ArcGis
{
    public class ArcGisRepository : IGisRepository
    {
        private IWorkspace workspace;
        internal ArcGisRepository(IPropertySet datasourceConfig)
        {
         //   IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass();
        //    workspace = workspaceFactory.Open(datasourceConfig, 0);
        }

        protected ArcGisRepository()
        {
        }
        protected ArcGisRepository(IWorkspace workspace)
        {
            this.workspace = workspace;
        }
        private ITable table;
        protected ITable ArcTable
        {
            get { return table; }
        }
        public ArcGisRepository(ITable table)
        {
            this.table = table;
        }
        public virtual void Save()
        {
        }
        public virtual void Delete()
        {
        }

        protected IGisTable GetTable(string layerName)
        {
            IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;
            return new ArcGisTable(featureWorkspace.OpenFeatureClass(
                workspace.ConnectionProperties.GetProperty("user").ToString() + "." + layerName));

        }
        internal IFeatureClass GetFeatureClass(string layerName)
        {
            IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;
            return featureWorkspace.OpenFeatureClass(workspace.ConnectionProperties.GetProperty("user").ToString() + "." + layerName);
        }

        public virtual object BuildDomain(IGisRow row)
        {
            throw new System.NotImplementedException();
        }
    }
}
